<?php

# http://projects:8081/cdapp-2kt-api/api/flow_ntfm_get_snapshot.php

include_once '_portal.php';

$from = (isset($post) && isset($post->from)) ? $post->from : null;
$to = (isset($post) && isset($post->to)) ? $post->to : null;

if (!$from || !$to) {
  output([
    'msg' => 'Invalid parameters',
    'success' => false,
    'tags' => null,
    'content' => null,
  ]);
  die();
}

$sql = "SELECT * FROM `2kt_flow_record_snapshot` WHERE `snapTime` >= '{$from}' AND `snapTime` <= '{$to}'";
$result = exec_sql($sql);

if (!$result) {
  output([
    'msg' => 'Failed to query flow record snapshot',
    'success' => false,
    'tags' => null,
    'content' => null,
  ]);
  die();
}

$snapData = query_parse($result);
$tags = get_param('flowTags');
$count = count($snapData);
output([
  'msg' => "Successfully loaded {$count} record(s)",
  'success' => true,
  'tags' => $tags,
  'content' => $snapData,
]);

die();
